//
//  UserWebService.m
//  YYZB
//
//  Created by BY_R on 16/3/25.
//
//

#import "UserWebService.h"

@implementation UserWebService

//登录
- (void)login:(NSString *)username
     password:(NSString *)password iphoneID:(NSString*)iphoneid
completionHanlder:(void (^)(NSArray *items, NSError *error))completionHanlder {
    NSString *URL = @"Helper/LoginByPsd";
    NSDictionary *params = @{
                             @"Mobile": username,
                             @"Password": password,
                             @"IMEI":iphoneid
                             
                             };
    NSString *URLString = [self formattedURLString:params method:URL sessionNeeded:NO];
    [self sendHTTPGetRequest:URLString completionHandler:^(id result, NSError *error) {
        if (error != nil) {
            completionHanlder(nil, error);
        } else {
            NSError *err;
            NSArray *items = [self unboxedValue:result error:&err];
            completionHanlder(items, err);
        }
    }];
}

//注册
- (void)registe:(NSString *)username VerifyCode:(NSString*)verifyCode
               password:(NSString *)password VerifyCodeId:(NSString*)codeId source:(NSString *)helpsource completionHanlder:(void (^)(NSArray *, NSError *))completionHanlder{
    NSString *URL = @"Helper/HelperRegister";
    NSDictionary *params = @{
                             @"Mobile": username,
                             @"VerifyCode":verifyCode,
                             @"Password": password,
                             @"VerifyCodeId":codeId,
                             @"HelperSource":helpsource
                             };
    NSString *URLString = [self formattedURLString:params method:URL sessionNeeded:NO];
    [self sendHTTPGetRequest:URLString completionHandler:^(id result, NSError *error) {
        if (error != nil) {
            completionHanlder(nil, error);
        } else {
            NSError *err;
            NSArray *items = [self unboxedValue:result error:&err];
            completionHanlder(items, err);
        }
    }];
}
//获取验证码
-(void)getVerifyCode:(NSString*)phoneNum flag:(NSString*)flag completionHanlder:(void (^)(NSArray *items, NSError *error))completionHanlder{
    
    NSString *URL = @"Customer/GetVerifyCode";
    NSDictionary *params = @{
                             @"Mobile": phoneNum,
                             @"RegFlag": flag,
                            };
    NSString *URLString = [self formattedURLString:params method:URL sessionNeeded:NO];
    [self sendHTTPGetRequest:URLString completionHandler:^(id result, NSError *error) {
        if (error != nil) {
            completionHanlder(nil, error);
        } else {
            NSError *err;
            NSArray *items = [self unboxedValue:result error:&err];
            completionHanlder(items, err);
        }
    }];
    
    
}
//忘记密码
- (void)forgetPsw:(NSString *)username VerifyCode:(NSString*)verifyCode
         password:(NSString *)password VerifyCodeId:(NSString*)codeId
completionHanlder:(void (^)(NSArray *items, NSError *error))completionHanlder{
    NSString *URL = @"Helper/RecoveryPassword";
    NSDictionary *params = @{
                             @"Mobile": username,
                             @"VerifyCode":verifyCode,
                             @"Password": password,
                             @"VerifyCodeId":codeId
                             };
    NSString *URLString = [self formattedURLString:params method:URL sessionNeeded:NO];
    [self sendHTTPGetRequest:URLString completionHandler:^(id result, NSError *error) {
        if (error != nil) {
            completionHanlder(nil, error);
        } else {
            NSError *err;
            NSArray *items = [self unboxedValue:result error:&err];
            completionHanlder(items, err);
        }
    }];
}
//AddAppSession记录
-(void)AddAPPSession:(NSString *)mobile Password:(NSString *)password IMEI:(NSString *)iphoneid completionHanlder:(void (^)(NSArray *, NSError *))completionHanlder{
    NSString * URL = @"Common/AddAppSession";
    NSDictionary * params = @{
                              @"Mobile": mobile,
                              @"Password": password,
                              @"IMEI":iphoneid
                              };
    NSString *URLString = [self formattedURLString:params method:URL sessionNeeded:NO];
    [self sendHTTPGetRequest:URLString completionHandler:^(id result, NSError *error) {
        if (error != nil) {
            completionHanlder(nil, error);
        } else {
            NSError *err;
            NSArray *items = [self unboxedValue:result error:&err];
            completionHanlder(items, err);
        }
    }];
}


//退出登录
-(void)logOut:(void (^)(NSArray *items, NSError *error))completionHanlder{
    NSString * URL = @"Helper/Logout";
    NSDictionary * params = @{
                              };
    NSString *URLString = [self formattedURLString:params method:URL sessionNeeded:YES];
    [self sendHTTPGetRequest:URLString completionHandler:^(id result, NSError *error) {
        if (error != nil) {
            completionHanlder(nil, error);
        } else {
            NSError *err;
            NSArray *items = [self unboxedValue:result error:&err];
            completionHanlder(items, err);
        }
    }];
}

//修改登录密码
-(void)updateLoginPsd:(NSString *)helpid oldpsd:(NSString *)oldpsd password:(NSString *)password completionHanlder:(void (^)(NSArray *, NSError *))completionHanlder{
    NSString * URL = @"RecruitHelper/UpdateHelperPassword";
    NSDictionary * params = @{
                              @"HelperId":helpid,
                              @"OldPassword":oldpsd,
                              @"LoginPassword":password
                              };
    NSString *URLString = [self formattedURLString:params method:URL sessionNeeded:YES];
    [self sendHTTPGetRequest:URLString completionHandler:^(id result, NSError *error) {
        if (error != nil) {
            completionHanlder(nil, error);
        } else {
            NSError *err;
            NSArray *items = [self unboxedValue:result error:&err];
            completionHanlder(items, err);
        }
    }];
}


//修改提现密码
-(void)updateDrawalPsd:(NSString *)helpid oldpsd:(NSString *)oldpsd password:(NSString *)password completionHanlder:(void (^)(NSArray *, NSError *))completionHanlder{
    NSString * URL = @"RecruitHelper/UpdateHelperWithdrawalPassword";
    NSDictionary * params = @{
                              @"HelperId":helpid,
                              @"OldPassword":oldpsd,
                              @"WithDrawingPassword":password
                              };
    NSString *URLString = [self formattedURLString:params method:URL sessionNeeded:YES];
    [self sendHTTPGetRequest:URLString completionHandler:^(id result, NSError *error) {
        if (error != nil) {
            completionHanlder(nil, error);
        } else {
            NSError *err;
            NSArray *items = [self unboxedValue:result error:&err];
            completionHanlder(items, err);
        }
    }];
}


- (void)fetchSaveGPSFrequencyCompletionHanlder:(void (^)(NSArray *items, NSError *error))completionHanlder {
    NSString *URL = @"Errand/GetServiceType";
    NSDictionary *params = @{
                             @"TypeCode": @"GetSaveGPSFrequency",
                             @"DicCode": @""
                             };
    NSString *URLString = [self formattedURLString:params method:URL sessionNeeded:NO];
    [self sendHTTPGetRequest:URLString completionHandler:^(id result, NSError *error) {
        if (error != nil) {
            completionHanlder(nil, error);
        } else {
            NSError *err;
            NSArray *items = [self unboxedValue:result error:&err];
            completionHanlder(items, err);
        }
    }];
}

- (void)saveHelperGPSWithLatitude:(NSNumber *)latitude
                        longitude:(NSNumber *)longitude
                completionHanlder:(void (^)(NSArray *items, NSError *error))completionHanlder {
    NSString *URL = @"Helper/SaveHelperGPS";
    NSDictionary *params = @{
                             @"Longitude": longitude,
                             @"Latitude": latitude
                             };
    NSString *URLString = [self formattedURLString:params method:URL sessionNeeded:NO];
    [self sendHTTPGetRequest:URLString completionHandler:^(id result, NSError *error) {
        if (error != nil) {
            completionHanlder(nil, error);
        } else {
            NSError *err;
            NSArray *items = [self unboxedValue:result error:&err];
            completionHanlder(items, err);
        }
    }];
}













@end
